package com.dylan.datacollection;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.MenuItem;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.dylan.datacollection.entity.MsgEntity;
import com.dylan.datacollection.net.HttpConfig;

public class MsgDetailActivity extends AppCompatActivity {
    ImageView imageView;
    TextView msgContentTextView;
    WebView webView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_msg_detail);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        imageView = (ImageView) findViewById(R.id.msg_img);
        msgContentTextView = (TextView) findViewById(R.id.msg_content);
        MsgEntity msgEntity = (MsgEntity) getIntent().getSerializableExtra("msg");
        webView = (WebView) findViewById(R.id.msg_webView);
        webView.loadUrl(HttpConfig.HOST+HttpConfig.H5+"?id="+msgEntity.getId());
        setTitle(msgEntity.getTitle());
        msgContentTextView.setText(msgEntity.getContent());
        if (!TextUtils.isEmpty(msgEntity.getImg())){
            Glide.with(this).load(msgEntity.getImg()).placeholder(R.mipmap.ic_default).thumbnail(0.1f).error(R.mipmap.ic_default).skipMemoryCache(false).into(imageView);
        }
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                this.finish(); // back button
                return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
